package com.ibeeking.found.common.enums;

import com.ibeeking.nematos.exception.BusinessException;

/**
 * @Author ibeeking
 * @Date: 2019-04-26 16:04
 * @Description:
 */
public enum ValidStatusEnum {
    /**
     * 启用
     */
    ENABLE(1, "已生效"),

    /**
     * 禁用
     */
    DISABLE(0, "未生效"),;

    private Integer value;
    private String name;

    ValidStatusEnum(int value, String name) {
        this.value = value;
        this.name = name;
    }

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static String getName(Integer value) {
        for (ValidStatusEnum ele : values()) {
            if (ele.getValue().equals(value)) {
                return ele.getName();
            }
        }
        return DISABLE.getName();
    }

    /**
     * 删除或修改数据前,发布状态校验(如果发布状态为'启用'则抛出异常)
     *
     * @param publishStatus
     */
    public static void statusCheckException(Integer publishStatus) {
        if (publishStatus == null) {
            return;
        }
        if (ENABLE.getValue().equals(publishStatus)) {
            throw new BusinessException("禁止对启用状态下的数据进行删除或修改操作!");
        }
    }
}
